package com.yuehuanghun.admin.generator.model.generator;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.yuehuanghun.framework.util.DatabaseUtil;
import com.yuehuanghun.framework.util.StringUtils;

@Component
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DaMengTableGenerator extends AbstractTableGenerator {

	@Override
	public String getDbName() {
		return DatabaseUtil.DataBase.DAMENG.getDbName();
	}
	
	@Override
	public String getSchema() { //自动获取当前连接用户为schema
		if(StringUtils.isBlank(schema)) {
			this.schema = getConnectedUser();
		}
		return schema;
	}

	private String getConnectedUser() {
		return jdbcTemplate.queryForObject("SELECT USER FROM DUAL", String.class);
	}
}
